<template>
	<view class="mainpadding beijingse">
		<view class="flexbetween mainpadding ffffff radius">
			<view class="ershib">真实姓名</view>
			<input class="inputs textright" type="text" placeholder="请输入真实姓名" v-model="real_name">
		</view>
		<view class="flexbetween mainpadding ffffff radius margin_top">
			<view class="ershib">身份证号</view>
			<input class="inputs textright" type="text" placeholder="请输入身份证号" v-model="id_card">
		</view>
		<view class="flexbetween margin_top">
			<view class="scsfz" v-if="upImg">
				<image :src="upImg" mode=""></image>
			</view>
			<view class="scsfz" @click="uploadImg" v-if="!upImg">
				<image src="../../static/image/system/sfzzm.png" mode=""></image>
			</view>
			<view class="scsfz" v-if="upImg1">
				<image :src="upImg1" mode=""></image>
			</view>
			<view class="scsfz" @click="uploadImg1" v-if="!upImg1">
				<image src="../../static/image/system/sfzfm.png" mode=""></image>
			</view>
		</view>
		<!-- 固定底部 -->
		<view class="gudingdb" @click="smrz">
			<view class="bigbtn">提交审核</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				upImg: "",
				upImg1: "",
				id_card: "",
				real_name: "",

			}
		},
		methods: {
				// 实名认证
			smrz(){
				uni.showLoading({
					title: '请稍候...',
					mask: true
				})
				if (this.real_name == "") {
					uni.hideLoading()
					httpRequest.toast("请输入真实姓名")
					return
				}
				if (this.id_card == "") {
					uni.hideLoading()
					httpRequest.toast("请输入身份证号")
					return
				}
				let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
				if (reg.test(this.id_card) === false) {
					httpRequest.toast("请输入正确的身份证号")
					uni.hideLoading()
					return false;
				}
				if (this.upImg == "") {
					uni.hideLoading()
					httpRequest.toast("请上传身份证头面像")
					return
				}
				if (this.upImg1 == "") {
					uni.hideLoading()
					httpRequest.toast("请上传身份证国徽面")
					return
				}
				httpRequest.request('/api/user/realnameRz', 'POST', {
					// 传参
					real_name: this.real_name, //持卡人
					id_card: this.id_card, //银行卡号
					id_card_zimage: this.upImg, //开户行
					id_card_fimage: this.upImg1, //开户行地址
				}, false, false, true).then(res => {
					if (res.code == 1) {
						httpRequest.toast(res.msg)
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			uploadImg() {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						console.log(res)
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i])
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									console.log(res[i])
									_this.uploadImageService(res[i])
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageService(url) {
				let _this = this;
				httpRequest.uploadFile('/api/Common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.upImg = image_item
				}).catch(err => {});
			},
			uploadImg1() {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						console.log(res)
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService1(res[i])
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									console.log(res[i])
									_this.uploadImageService1(res[i])
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageService1(url) {
				let _this = this;
				httpRequest.uploadFile('/api/Common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.upImg1 = image_item
				}).catch(err => {});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.scsfz {
		width: 48%;
		height: 291rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.inputs {
		width: 60%;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}
</style>
